package com.app.business.service;


import com.app.business.model.StorageRoomBuyPerson;
import com.app.system.jpa.JpaBaseDao;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by ddz on 2019/2/27.
 */
@Service
@SuppressWarnings("all")
public class StorageRoomPersonService extends JpaBaseDao<StorageRoomBuyPerson, Integer> {
    /**
     * 通过storageRoomId得到HouseBuyPerson中的产权人id
     * @param houseId
     * @return
     */
    @Transactional
    public List<String> getBuyHousePersonIdListByStorageRoomId(Integer storageRoomId) {
        String sql = "select buy_house_person_id from storage_room_buy_person  where storage_room_id =:storageRoomId";
        return this.entityManager.createNativeQuery(sql).setParameter("storageRoomId", storageRoomId).getResultList();
    }

    @Transactional
    public List<Integer> getBuyHousePersonIdListByStorageRoomIdForInteger(Integer storageRoomId) {
        String sql = "select buy_house_person_id from storage_room_buy_person  where storage_room_id =:storageRoomId";
        return this.entityManager.createNativeQuery(sql).setParameter("storageRoomId", storageRoomId).getResultList();
    }


    /**
     * 通过storageRoomId删除关联储藏间的产权人
     *
     * @param storageRoomId
     */
    @Transactional
    public synchronized void deleteStorageRoomBuyPersonByStorageRoomId(Integer storageRoomId) {
        String sql = "delete from storage_room_buy_person  where storage_room_id =:storageRoomId";
        this.entityManager.createNativeQuery(sql).setParameter("storageRoomId", storageRoomId).executeUpdate();
    }

    /**
     * 通过buyHousePersonId删除储物间关联的产权人
     *
     * @param buyHousePersonId
     */
    @Transactional
    public synchronized void deleteStorageRoomBuyPersonByBuyHousePersonId(Integer buyHousePersonId) {
        //查询语句
        String sql = "delete from storage_room_buy_person  where buy_house_person_id =:buyHousePersonId";
        this.entityManager.createNativeQuery(sql).setParameter("buyHousePersonId", buyHousePersonId).executeUpdate();
    }
}
